﻿using System;
using System.Windows.Automation;

namespace QuickUIT.Controls
{
    /// <summary>
    /// Represents a slider control. 
    /// </summary>
    public class UISlider : UIBaseControl
    {
        /// <summary>
        /// Gets the maximum value for the slider control. 
        /// </summary>
        public new double Maximum
        {
            get { return base.Maximum; }
        }

        /// <summary>
        /// Gets the minimum value for the slider control.
        /// </summary>
        public new double Minimum
        {
            get { return base.Minimum; }
        }

        /// <summary>
        /// Specifies the current range value for the slider control. 
        /// </summary>
        public new double RangeValue
        {
            get { return base.RangeValue; }
            set { SetRangeValue(value); }
        }

        /// <summary>
        /// Gets whether the slider control is in a read-only state. 
        /// </summary>
        public new bool IsRangeReadOnly
        {
            get { return base.IsRangeReadOnly; }
        }

        /// <summary>
        /// Gets the large change slider value. 
        /// </summary>
        public new double LargeChange
        {
            get { return base.LargeChange; } 
        }

        /// <summary>
        /// Gets the small change slider value. 
        /// </summary>
        public new double SmallChange
        {
            get { return base.SmallChange; } 
        }

        /// <summary>
        /// Gets whether the slider value is read-only. 
        /// </summary>
        public new bool IsReadOnly
        {
            get { return base.IsReadOnly; }
        }
        /// <summary>
        /// Specifies the value of the slider, if content represents one value among a discrete set of options.
        /// </summary>
        public new string Value
        {
            get { return base.Value; }
            set { SetValue(value); }
        }

        /// <summary>
        /// Gets whether the slider can allows more than one child element to be selected concurrently.
        /// </summary>
        public new bool CanSelectMultiple
        {
            get { return base.CanSelectMultiple; }
        }

        /// <summary>
        /// Gets whether the slider requires at least one child element to be selected.
        /// </summary>
        public new bool IsSelectionRequired
        {
            get { return base.IsSelectionRequired; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UISlider"/> class. 
        /// </summary>
        public UISlider()
            : base(ControlType.Slider)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UISlider"/> class.
        /// </summary>
        /// <param name="parent">The parent of this control.</param>
        public UISlider(UIBaseControl parent)
            : base(parent, ControlType.Slider)
        { 
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UISlider"/> class.
        /// </summary>
        /// <param name="locator">The locator used to find the specific control.</param>
        public UISlider(string locator)
            : base(null, ControlType.Slider, locator)
        { 
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UISlider"/> class.
        /// </summary>
        /// <param name="parent">The parent of this control.</param>
        /// <param name="locator">The locator used to find the specific control.</param>
        public UISlider(UIBaseControl parent, string locator)
            : base(parent, ControlType.Slider, locator)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UISlider"/> class.
        /// </summary>
        /// <param name="control">The underlying <see cref="AutomationElement"/> of the control.</param>
        public UISlider(AutomationElement control) : base(control, ControlType.Slider)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UISlider"/> class.
        /// </summary>
        /// <param name="parent">The parent of the control</param>
        /// <param name="control">The underlying <see cref="AutomationElement"/> of the control.</param>
        public UISlider(UIBaseControl parent, AutomationElement control) : base(parent, control, ControlType.Slider)
        {
        }

        /// <summary>
        /// Sets the value of the slider.
        /// </summary>
        /// <param name="value">The new value of the slider.</param>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public new void SetRangeValue(double value)
        {
            base.SetRangeValue(value);
        }

        /// <summary>
        /// Decrements the slider control by a small change value.  
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if the decremented value is less than the minimum range value of the control.</exception>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public void DecrementBySmallChange()
        {
            WaitForParentWindowToBeReady();
            SetRangeValue(RangeValue - SmallChange); 
        }

        /// <summary>
        /// Increments the slider control by a small change value.  
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if the incremented value is greater than the maximum range value of the control.</exception>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public void IncrementBySmallChange()
        {
            WaitForParentWindowToBeReady();
            SetRangeValue(RangeValue + SmallChange); 
        }

        /// <summary>
        /// Decrements the slider control by a large change value.  
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if the decremented value is less than the minimum range value of the control.</exception>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public void DecrementByLargeChange()
        {
            WaitForParentWindowToBeReady();
            SetRangeValue(RangeValue - LargeChange);
        }

        /// <summary>
        /// Increments the slider control by a large change value.  
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if the incremented value is greater than the maximum range value of the control.</exception>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public void IncrementByLargeChange()
        {
            WaitForParentWindowToBeReady();
            SetRangeValue(RangeValue + LargeChange);
        }

        /// <summary>
        /// Gets a collection of automation elements that represents the current selection for an element.
        /// </summary>
        /// <returns>A collection of selected elements.</returns>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public new AutomationElement[] GetSelection()
        {
            return base.GetSelection(); 
        }
    }
}
